import { OVComponent, IObjectView, ObjectViewInfo } from '@feng3d/objectview';
import { Div, Span, Image } from '../components/UI';

/**
 * 默认基础对象界面
 */
@OVComponent()
export class OVBaseDefault extends Div implements IObjectView
{
    public label: Span;
    public image: Image;
    //
    private _space: Object;

    constructor(_objectViewInfo: ObjectViewInfo)
    {
        super();

        this.label = new Span();
        this.image = new Image();
        this.addChild(this.label);
        this.addChild(this.image);

        this.updateView();
    }

    get space(): Object
    {
        return this._space;
    }

    set space(value: Object)
    {
        this._space = value;
        this.updateView();
    }

    getAttributeView(_attributeName: String)
    {
        return null;
    }

    getblockView(_blockName: String)
    {
        return null;
    }

    /**
     * 更新界面
     */
    updateView(): void
    {
        this.image.visible = false;
        this.label.visible = true;
        const value = this._space;
        if (typeof value === 'string' && value.indexOf('data:') === 0)
        {
            this.image.visible = true;
            this.label.visible = false;
            this.image.source = value;
        }
 else
        {
            let string = String(value);
            if (string.length > 1000)
                { string = `${string.substr(0, 1000)}\n.......`; }
            this.label.text = string;
        }
    }
}
